package com.uhuibao.tmall.api.domain.vo;


import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

/**
 * 充值请求参数
 *
 * @author haungzj
 * @date 2023-09-11
 */
public class OrderQueryRequest {

    /**
     * 淘宝订单号
     */
    @NotNull(message = "tbOrderNo不能为空")
    private Long tbOrderNo;

    /**
     * 业务类型，枚举值参考附录
     */
    @NotNull(message = "bizType不能为空")
    @NotBlank(message = "bizType不能为空")
    private String bizType;


    /**
     * 商家唯一编号，等于淘宝卖家sellerId
     */
    @NotNull(message = "supplierId不能为空")
    private Long supplierId;


    /**
     * 淘宝发起本次请求时的时间戳
     */
    @NotNull(message = "ts不能为空")
    private Long ts;

    /**
     * 签名，签名方法参考附录
     */
    @NotNull(message = "sign不能为空")
    @NotBlank(message = "sign不能为空")
    private String sign;

    public Long getTbOrderNo() {
        return tbOrderNo;
    }

    public void setTbOrderNo(Long tbOrderNo) {
        this.tbOrderNo = tbOrderNo;
    }

    public String getBizType() {
        return bizType;
    }

    public void setBizType(String bizType) {
        this.bizType = bizType;
    }
    
    public Long getSupplierId() {
        return supplierId;
    }

    public void setSupplierId(Long supplierId) {
        this.supplierId = supplierId;
    }

    public Long getTs() {
        return ts;
    }

    public void setTs(Long ts) {
        this.ts = ts;
    }

    public String getSign() {
        return sign;
    }

    public void setSign(String sign) {
        this.sign = sign;
    }

    public Long getDecodedTbOrderNo() {
        return tbOrderNo;
    }

    public String getDecodedBizType() {
        return decodeParam(bizType);
    }

    public Long getDecodedSupplierId() {
        return supplierId;
    }

    public Long getDecodedTs() {
        return ts;
    }

    public String getDecodedSign() {
        return decodeParam(sign);
    }

    private String decodeParam(String param) {
        if (param != null) {
            try {
                // 手动进行URL解码
                return URLDecoder.decode(param, "GBK");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}
